package service.impl;

import service.ProductService;
import ssm.dao.impl.ProductDaoImpl;
import ssm.pojo.PageBean;
import ssm.pojo.Product;

import java.sql.SQLException;
import java.util.List;

public class ProductServiceImpl implements ProductService {

    @Override
    public List<Product> findCateBydate() {
        try {
            ProductDaoImpl categoryDao = new ProductDaoImpl();
            List<Product> cateBydate = categoryDao.findCateBydate();
            if (cateBydate != null) {
                return cateBydate;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public List<Product> findHot() {
        try {
            ProductDaoImpl pd = new ProductDaoImpl();
            List<Product> hotDate = pd.findHotDate();
            if (hotDate != null) {
                return hotDate;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public Product findPById(String pid) {
        try {
            ProductDaoImpl pd = new ProductDaoImpl();
            Product proById = pd.findProById(pid);
            if (proById != null) {
                return proById;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public PageBean<Product> CateByProduct(int nummber, int total, String cid) {
        try {
            ProductDaoImpl pd = new ProductDaoImpl();
            List<Product> proByLimit = pd.findProByLimit(nummber, total, cid);
            int countPro = pd.findCountPro(cid);
            return new PageBean<>(nummber,total,countPro,proByLimit);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
